﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using NetAcademia.Web.Mvc.ImageRendering;
using System.Data.SqlClient;
using NetAcademia.Configuration;
using System.Configuration;

namespace NetAcademia.Web.Mvc.Controllers
{
    public class XAMLtoMVCController : Controller
    {
        [HttpGet]
        [OutputCache(CacheProfile="Tacepao")]
        public FileContentResult Tacepao(string id, TacepaoRuntimeParameters runtimeParams)
        {
            XamlToPng renderer = new XamlToPng();
            var result = renderer.GetPngFromTacepaoXaml(id, runtimeParams,ControllerContext.RequestContext.HttpContext.Request.QueryString, ControllerContext.HttpContext.Server);
            return File(result.Bits, result.ContentType, result.DownloadFileName);
        }

        [HttpGet]
        [OutputCache(CacheProfile="SqlImage")]
        public FileContentResult SqlImage(string id, SqlImageRuntimeParameters runtimeParams)
        {
            XamlToPng renderer = new XamlToPng();
            var result = renderer.GetPngFromImageXaml(id, runtimeParams, ControllerContext.RequestContext.HttpContext.Request.QueryString, ControllerContext.HttpContext.Server);
            return File(result.Bits, result.ContentType, result.DownloadFileName);
        }

        [HttpGet]
        [OutputCache(CacheProfile = "XamlToPng")]
        public FileContentResult XamlToPng(string id)
        {
            XamlToPng renderer = new XamlToPng();
            var result = renderer.GetPngFromXaml(id, ControllerContext.RequestContext.HttpContext.Request.QueryString, ControllerContext.HttpContext.Server);
            return File(result.Bits, result.ContentType, result.DownloadFileName);
        }

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public void SqlImageRaw(string id, string downloadfilename)
        {
            XamlToPng renderer = new XamlToPng();
            renderer.WriteImageFromSql(id, ControllerContext.RequestContext.HttpContext.Request.QueryString, ControllerContext.HttpContext, downloadfilename);
        }


     

    }
}
